from event_rule.dwc.product_event_rule.game_aggregate_report import GAME_AGGREGATE_REPORT
from event_rule.dwc.product_event_rule.bet_user_analysis import BET_USER_ANALYSIS_CONFIG
from event_rule.dwc.product_event_rule.fish_profit_report import FISH_PROFIT_REPORT
from common.es_core import report_creator
from common.const import IntervalType


def _get_game_aggregate_analysis_key_mapper(index, required_room=None, required_game=None, required_chn=None,
                                            time_interval_type='hour'):
    additional_key_mapper = [
        {"key": "day", "name": "日期"},
    ]
    if time_interval_type == IntervalType.HOUR.value:
        additional_key_mapper += [{'key': 'hour', 'name': "时段"}]
    if required_chn:
        additional_key_mapper += [{'key': "_chn", "name": '渠道'}]
    additional_key_mapper += [
        {'key': "game_name", "name": "游戏名称"},
        {'key': "room_name", "name": "房间名称"}
    ]
    additional_key_mapper.append(
        {'key': "new_bet_user", "name": "新增投注账号", 'default': '-',
         'description': '当日前未进入游戏任一房间，\n于当日参与投注的用户数，各房间独立计算，\n合计时去重'})
    additional_key_mapper.append({'key': "new_recharge_bet_user", "name": "新增充值投注账号", 'default': '-',
                                  'description': '当日前未进入游戏任一房间，\n于当日充值并参与投注的用户数，\n各房间独立计算，合计时去重'})
    if required_room:
        additional_key_mapper.append(
            {'key': "limit", "name": "门槛", 'default': '-', 'description': '游戏房间门槛，游戏底分(左) / 金币要求(右)'})
    key_mapper = report_creator.get_key_mapper_list(GAME_AGGREGATE_REPORT.get('values'), index)
    key_mapper = additional_key_mapper + key_mapper
    return key_mapper


def _get_bet_user_analysis_key_mapper(index):
    config = BET_USER_ANALYSIS_CONFIG
    additional_key_mapper = [
        {'key': "game_name", "name": "游戏名称"},
        {'key': "room_name", "name": "房间名称"}
    ]
    key_mapper_dct = report_creator.get_key_mapper_list(config.get('values'), index)
    return [{'key': 'day', 'name': '活跃时间'},
            {'key': '_user_id', 'name': "用户ID"},
            {'key': 'registered_at', 'name': '注册时间'},
            {'key': 'chn', 'name': '渠道'}] + additional_key_mapper + key_mapper_dct


def _get_fish_profit_analysis_key_mapper(index, time_interval_type=None, user_id=None):
    config = FISH_PROFIT_REPORT
    additional_key_mapper = [
        {"key": "day", "name": "日期"},
    ]
    if time_interval_type == IntervalType.HOUR.value:
        additional_key_mapper += [{'key': 'hour', 'name': "时段"}]
    if user_id:
        additional_key_mapper += [{'key': '_user_id', 'name': "用户ID"}]
    additional_key_mapper += [
        {'key': 'room_id', 'name': "房间"},
        {'key': 'fishing_bet_item_fish_type', 'name': '鱼种'}
    ]
    key_mapper_list = report_creator.get_key_mapper_list(config.get('values'), index)
    return additional_key_mapper + key_mapper_list


KEY_MAPPER_FUNC = {
    '2004': _get_game_aggregate_analysis_key_mapper,
    '2005': _get_bet_user_analysis_key_mapper,
    '2007': _get_fish_profit_analysis_key_mapper
}
